package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.GenerateService;
import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.dao.Record;
import com.jzoom.zoom.web.annotations.Controller;
import com.jzoom.zoom.web.annotations.JsonResponse;
import com.jzoom.zoom.web.annotations.Mapping;

@Controller(key="gen")
public class GenerateController  implements AdminController{
	
	public GenerateController() {
		
		
	}
	
	@Inject
	private GenerateService generateService;


	@Inject(value = "admin")
	private Dao admin;
	
	@Mapping(value="template",method=Mapping.POST)
	@JsonResponse
	public int template(
			String table, 
			String type,
			int ds) {
		
		Record d = admin.ar().table("sys_datasource").where("id", ds).get();
		if(d==null) {
			throw new RuntimeException("没有找到数据源");
		}
		generateService.generatePage(type, d.getString("key"), table);
		return 0;
	}
	
	
	
	
}
